package com.appclub.kitsilano.other;


import com.appclub.kitsilano.bulletin.PDFdownloader;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

public class StartupReceiver extends BroadcastReceiver {
	@Override
	public void onReceive(Context context, Intent intent) {

		String action = intent.getAction();
		if (action.equals("android.intent.action.BOOT_COMPLETED")) {
			Intent serviceIntent = new Intent(context, Service_.class);
			context.startService(serviceIntent);
			Intent serviceIntent2 = new Intent(context, PDFdownloader.class);
			serviceIntent2.putExtra("Bulletin", 3);
			context.startService(serviceIntent2);
		}
		if (action.equals(Intent.ACTION_TIME_TICK)) {
			Intent serviceIntent = new Intent(context, Service_.class);
			context.startService(serviceIntent);
			Intent serviceIntent2 = new Intent(context, PDFdownloader.class);
			serviceIntent2.putExtra("Bulletin", 3);
			context.startService(serviceIntent2);
		}
		IntentFilter filter = new IntentFilter();
		filter.addAction(Intent.ACTION_TIME_TICK);
		context.getApplicationContext().registerReceiver(this, filter);

		if (action.equals(Intent.ACTION_PACKAGE_ADDED)
				| action.equals(Intent.ACTION_PACKAGE_CHANGED)
				| action.equals(Intent.ACTION_PACKAGE_INSTALL)
				| action.equals(Intent.ACTION_PACKAGE_REPLACED)
				| action.equals(Intent.ACTION_SCREEN_OFF)) {
			Intent serviceIntent = new Intent(context, Service_.class);
			context.startService(serviceIntent);
			Intent serviceIntent2 = new Intent(context, PDFdownloader.class);
			serviceIntent2.putExtra("Bulletin", 3);
			context.startService(serviceIntent2);
		}
	}
}